<template>
  <div class="dashboard-container">
    <div class="dashboard-text">欢迎登录:{{ name }}</div>
    <div class="dashboard-text">今天时间: <span>{{ time }}</span></div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  data: function() {
    return {
      timer: null,
      time: ''
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ])
  },
  mounted: function() {
    this.timer = setInterval(() => {
      const myDate = new Date()
      this.time = myDate.getFullYear() + '年' + (myDate.getMonth() + 1) + '月' + myDate.getDate() + '日 ' + myDate.toLocaleTimeString()
    }, 1000)
  },
  beforeDistroyed: function() {
    // 在vue实例销毁钱，清除我们的定时器
    clearInterval(this.timer)
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
